home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0800 / winsock.pas < prev   
Pascal/Delphi Source File  |  1997-04-10  |  8KB  |  175 lines

  1. unit WINSOCK;
  2.  
  3. { Winsock.h file for Borland Pascal
  4.   Conversion by Marc B. Manza
  5.              Center for Applied Large-Scale Computing
  6.   Requires Winsock.pas and Winsock.inc
  7.  
  8.   Send any comments/change requests/etc. to:
  9.   manza@flash.poly.edu }
  10.  
  11. {
  12.   Modified by Mike Caughran Cedar Island Software
  13.   Added gethostname.
  14.   changed _socket() to socket().
  15.   changed references to SOCKET to tSOCKET.
  16.   changed accept parms from tSocket,SockAddr,Integer 
  17.                          to tSocket,PSockAddr,PInteger
  18. }
  19.  
  20. interface
  21.  
  22. uses WIN31, WinTypes, WinProcs;
  23.  
  24. {$I winsock.inc }
  25.  
  26. { Library Functions }
  27.  
  28.   function accept (s : tSOCKET; addr : PSockaddr; addrlen : PInteger) : tSOCKET;
  29.   function bind (s : tSOCKET; addr : sockaddr; namelen : integer) : integer;
  30.   function closesocket (s : tSOCKET) : integer;
  31.   function connect (s : tSOCKET; name : sockaddr; namelen : integer) : integer;
  32.   function ioctlsocket (s : tSOCKET; cmd : longint; argp : u_long) : integer;
  33.   function getpeername (s : tSOCKET; name : sockaddr; namelen : integer) : integer;
  34.   function getsockname (s : tSOCKET; name : sockaddr; namelen : integer) : integer;
  35.   function getsockopt (s : tSOCKET; level, optname : integer; optval : PChar; optlen : integer) : integer;
  36.   function htonl (hostlong : u_long) : u_long;
  37.   function htons (hostshort : u_short) : u_short;
  38.   function inet_addr (cp : PChar) : PIn_Addr;  { in_addr }
  39.   function inet_ntoa (inaddr : in_addr) : PChar;
  40.   function listen (s : tSOCKET; backlog : integer) : integer;
  41.   function ntohl (netlong : u_long) : u_long;
  42.   function ntohs (netshort : u_short) : u_short;
  43.   function recv (s : tSOCKET; buf : PChar; len, flags : integer) : integer;
  44.   function recvfrom (s : tSOCKET; buf : PChar; len, flags : integer; from : sockaddr; fromlen : integer) : integer;
  45.   function select (nfds : integer; readfds, writefds, exceptfds : fd_set; timeout : timeval) : longint;
  46.   function send (s : tSOCKET; buf : PChar; len, flags : integer) : integer;
  47.   function sendto (s : tSOCKET; buf : PChar; len, flags : integer; addrto : sockaddr; tolen : integer) : integer;
  48.   function setsockopt (s : tSOCKET; level, optname : integer; optval : PChar; optlen : integer) : integer;
  49.   function shutdown (s : tSOCKET; how : integer) : integer;
  50.   function socket (af, struct, protocol : integer) : tSOCKET;
  51.   function gethostbyaddr (addr : PChar; len, struct : integer) : PHostEnt; { hostent }
  52.   function gethostbyname (name : PChar) : PHostEnt; { hostent }
  53.   function gethostname (name : PChar; len : integer) : integer;
  54.   function getservbyport (port : integer; proto : PChar) : PServEnt; { servent }
  55.   function getservbyname (name, proto : PChar) : PServEnt; { servent }
  56.   function getprotobynumber (proto : integer) : PProtoEnt; { protoent }
  57.   function getprotobyname (name : PChar) : PProtoEnt; { protoent }
  58.   function WSAStartup (wVersionRequired : word; lpWSData : LPWSADATA) : integer;
  59.   function WSACleanup : integer;
  60.   procedure WSASetLastError (iError : integer);
  61.   function WSAGetLastError : integer;
  62.   function WSAIsBlocking : BOOL;
  63.   function WSAUnhookBlockingHook : integer;
  64.   function WSASetBlockingHook (lpBlockFunc : TFarProc) : TFarProc;
  65.   function WSACancelBlockingCall : integer;
  66.   function WSAAsyncGetServByName (HWindow : HWND; wMsg : u_int; name, proto, buf : PChar; buflen : integer) : THandle;
  67.   function WSAAsyncGetServByPort ( HWindow : HWND; wMsg, port : u_int; proto, buf : PChar; buflen : integer) : THandle;
  68.   function WSAAsyncGetProtoByName (HWindow : HWND; wMsg : u_int; name, buf : PChar; buflen : integer) : THandle;
  69.   function WSAAsyncGetProtoByNumber (HWindow : HWND; wMsg : u_int; number : integer;
  70.                                       buf : PChar; buflen : integer) : THandle;
  71.   function WSAAsyncGetHostByName (HWindow : HWND; wMsg : u_int; name, buf : PChar; buflen : integer) : THandle;
  72.   function WSAAsyncGetHostByAddr (HWindow : HWND; wMsg : u_int; addr : PChar; len, struct : integer;
  73.                                   buf : PChar; buflen : integer) : THandle;
  74.   function WSACancelAsyncRequest (hAsyncTaskHandle : THandle) : integer;
  75.   function WSAAsyncSelect (s : tSOCKET; HWindow : HWND; wMsg : u_int; lEvent : longint) : integer;
  76.  
  77.  
  78. function WSAMakeSyncReply (Buflen, Error : Word) : LongInt;
  79. function WSAMakeSelectReply (Event, Error : Word) : LongInt;
  80. function WSAGetAsyncBuflen (Param : LongInt) : Word;
  81. function WSAGetAsyncError (Param : LongInt) : Word;
  82. function WSAGetSelectEvent (Param : LongInt) : Word;
  83. function WSAGetSelectError (Param : LongInt) : Word;
  84.  
  85. implementation
  86.  
  87. var
  88.    fdSet : fd_set;
  89.  
  90. function FIONBIO (x, y : integer; t : u_long) : u_long;
  91. begin
  92.      FIONBIO := (IOC_IN OR ((IOCPARM_MASK shl 16) OR (x SHL 8) OR (Y)));
  93. end;
  94.  
  95. function WSAMakeSyncReply;
  96. begin
  97.      WSAMakeSyncReply := MakeLong (Buflen, Error);
  98. end;
  99.  
  100. function WSAMakeSelectReply;
  101. begin
  102.      WSAMakeSelectReply := MakeLong (Event, Error);
  103. end;
  104.  
  105. function WSAGetAsyncBuflen;
  106. begin
  107.      WSAGetAsyncBuflen := LOWORD(Param);
  108. end;
  109.  
  110. function WSAGetAsyncError;
  111. begin
  112.      WSAGetAsyncError := HIWORD(Param);
  113. end;
  114.  
  115. function WSAGetSelectEvent;
  116. begin
  117.      WSAGetSelectEvent := LOWORD(Param);
  118. end;
  119.  
  120. function WSAGetSelectError;
  121. begin
  122.      WSAGetSelectError := HIWORD(Param);
  123. end;
  124.  
  125. function accept;            external    'WINSOCK' index 1;
  126. function bind;              external    'WINSOCK' index 2;
  127. function closesocket;       external    'WINSOCK' index 3;
  128. function connect;           external    'WINSOCK' index 4;
  129. function getpeername;       external    'WINSOCK' index 5;
  130. function getsockname;       external    'WINSOCK' index 6;
  131. function getsockopt;        external    'WINSOCK' index 7;
  132. function htonl;             external    'WINSOCK' index 8;
  133. function htons;             external    'WINSOCK' index 9;
  134. function inet_addr;         external    'WINSOCK' index 10;
  135. function inet_ntoa;         external    'WINSOCK' index 11;
  136. function ioctlsocket;       external    'WINSOCK' index 12;
  137. function listen;            external    'WINSOCK' index 13;
  138. function ntohl;             external    'WINSOCK' index 14;
  139. function ntohs;             external    'WINSOCK' index 15;
  140. function recv;              external    'WINSOCK' index 16;
  141. function recvfrom;          external    'WINSOCK' index 17;
  142. function select;            external    'WINSOCK' index 18;
  143. function send;              external    'WINSOCK' index 19;
  144. function sendto;            external    'WINSOCK' index 20;
  145. function setsockopt;        external    'WINSOCK' index 21;
  146. function shutdown;          external    'WINSOCK' index 22;
  147. function socket;            external    'WINSOCK' index 23;
  148.  
  149. function gethostbyaddr;     external    'WINSOCK' index 51;
  150. function gethostbyname;     external    'WINSOCK' index 52;
  151. function getprotobyname;    external    'WINSOCK' index 53;
  152. function getprotobynumber;  external    'WINSOCK' index 54;
  153. function getservbyname;     external    'WINSOCK' index 55;
  154. function getservbyport;     external    'WINSOCK' index 56;
  155. function gethostname;       external    'WINSOCK' index 57;
  156.  
  157. function WSAAsyncSelect;    external    'WINSOCK' index 101;
  158. function WSAAsyncGetHostByAddr; external 'WINSOCK' index 102;
  159. function WSAAsyncGetHostByName; external 'WINSOCK' index 103;
  160. function WSAAsyncGetProtoByNumber; external 'WINSOCK' index 104;
  161. function WSAAsyncGetprotoByName; external 'WINSOCK' index 105;
  162. function WSAAsyncGetServByPort; external 'WINSOCK' index 106;
  163. function WSAAsyncGetServByName; external 'WINSOCK' index 107;
  164. function WSACancelAsyncRequest; external 'WINSOCK' index 108;
  165. function WSASetBlockingHook; external    'WINSOCK' index 109;
  166. function WSAUnhookBlockingHook; external 'WINSOCK' index 110;
  167. function WSAGetLastError;    external    'WINSOCK' index 111;
  168. procedure WSASetLastError;   external    'WINSOCK' index 112;
  169. function WSACancelBlockingCall; external 'WINSOCK' index 113;
  170. function WSAIsBlocking;     external     'WINSOCK' index 114;
  171. function WSAStartup;        external     'WINSOCK' index 115;
  172. function WSACleanup;        external     'WINSOCK' index 116;
  173.  
  174. end.
  175.